package ch.fusun.baron.basic.turntask;

import ch.fusun.baron.city.City;
import ch.fusun.baron.city.api.CityService;
import ch.fusun.baron.core.injection.Configure;
import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.player.Player;
import ch.fusun.baron.player.api.Country;
import ch.fusun.baron.player.api.PlayerService;
import ch.fusun.baron.property.api.PropertyService;
import ch.fusun.baron.treasury.api.TreasuryService;
import ch.fusun.baron.turn.TurnTask;

/**
 * Calculates the income of the cities per player
 */
public class CityIncomeTurnTask implements TurnTask {

	@Configure(value = "10")
	private int MONEY_PER_CITY;
	@Inject
	private PlayerService playerService;
	@Inject
	private CityService cityService;
	@Inject
	private TreasuryService treasuryService;
	@Inject
	private PropertyService propertyService;

	@Override
	public void execute() {
		for (City city : cityService.getCities()) {
			Country country = (Country) propertyService
					.getOwnership(cityService.getLocation(city));
			Player owner = (Player) propertyService.getOwnership(country);
			treasuryService.addMoney(playerService.getDynasty(owner),
					MONEY_PER_CITY * city.getPopulation());
		}
	}

}
